<template>
  <div class="login-view">
    <router-link to="/owner">
      <van-nav-bar left-arrow :border="false" />
    </router-link>
    <div class="login-main-content">
      <div class="login-logo">
        <img :src="LoginLogo" />
      </div>
      <div class="form-wrap">
        <van-form @submit="onSubmit">
          <router-link to="/phoneArea">
            <van-field arrow-direction :is-link="true" :readonly="true" :value="country" />
          </router-link>
          <van-field
            v-model="tel"
            type="tel"
            placeholder="请输入手机号码"
            :rules="[{message: '手机号码有误' }]"
            :maxlength="11"
          />
          <van-field
            v-model="digit"
            type="digit"
            placeholder="请输入手机验证码"
            :rules="[{message: '验证码错误' }]"
            :maxlength="4"
          >
            <template #button>
              <van-button size="small" type="primary">获取验证码</van-button>
            </template>
          </van-field>
          <div class="login-submit-button">
            <van-button block type="info" native-type="submit">确定</van-button>
          </div>
        </van-form>
        <p class="tips">
          点击确定，即表示以阅读并同意
          <router-link to="/protocal">《注册会员服务条款》</router-link>
        </p>
      </div>
      <van-number-keyboard
        :show="show"
        :maxlength="6"
        @blur="show = false"
        @input="onInput"
        @delete="onDelete"
      />
    </div>
  </div>
</template>
<script>
import LoginLogo from "../../assets/login-logo.png";
export default {
  data() {
    return {
      tel: "",
      digit: "",
      country: "",
      LoginLogo,
      show: false
    };
  },
  mounted() {
    this.getCountryInfo();
  },
  watch: {
    $route: "getCountryInfo"
  },
  methods: {
    onSubmit(values) {
      console.log("submit", values);
    },
    downKeyBoard() {
      document.activeElement.blur();
    },
    onInput(value) {
      this.username += value;
    },
    onDelete() {
      this.username = "";
    },
    getCountryInfo() {
      let numInfo = this.$store.state.countryNumber;
      let nameInfo = this.$store.state.countryName;
      this.country = nameInfo + "（" + numInfo + "）";
    }
  }
};
</script>
<style lang="less" scoped>
.login-main-content,
.login-view {
  height: 100%;
  background-color: #ffffff;
}
.login-main-content {
  padding-top: 26px;
}
.van-nav-bar__left {
  .van-icon-arrow-left {
    color: rgba(44, 44, 44, 1);
  }
}
.login-logo {
  img {
    width: 80px;
    height: 94px;
    display: block;
    margin: auto;
  }
}
.login-submit-button {
  margin-top: 19px;
  .van-button {
    background-color: #528dc5;
    border-radius: 5px;
    opacity: 0.8;
  }
}
.van-field__button {
  .van-button {
    background-color: #528dc5;
    border: transparent;
  }
}
.form-wrap {
  margin: 57px auto 0 auto;
  width: 80%;
  .tips {
    color: #808080;
    font-size: 12px;
    margin: 10px 0 0 0;
    text-align: center;
    a {
      color: #557a9d;
      text-decoration: none;
    }
  }
  .van-cell {
    padding: 10px 0;
    &::after {
      left: 0;
    }
  }
}
</style>